#coding:utf-8
"""Copyright (c) 2022 God Forever
Online-class Efficiency Optimizer is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details."""
from tkinter import *
from tkinter import ttk
from tkinter.messagebox import *
def myfunction(event):
    aaaaa.configure(scrollregion=aaaaa.bbox("all"), width=200, height=200)
def doit(event,c):
    global ls,l2s,l3s,l4s,ln,a,d,f,abcde,edcba
    try:
        if abcde==1:
            tian2(1)
            abcde=0
    except:
        if False:
            print()
    try:
        if edcba==1:
            gai2(1)
            edcba=0
    except:
        if False:
            print()
    try:
        ls[ln]["bg"] = "white"
        l2s[ln]["bg"] = "white"
        l3s[ln]["bg"] = "white"
        l4s[ln]["bg"] = "white"
    except:
        if False:
            print()
    ls[c]["bg"] = "#99d9ea"
    l2s[c]["bg"] = "#99d9ea"
    l3s[c]["bg"] = "#99d9ea"
    l4s[c]["bg"] = "#99d9ea"
    d["state"]="normal"
    f["state"]="normal"
    ln=c
def shan():
    global ls, l2s, l3s,l4s,ln, a,d, f,things
    from tkinter.messagebox import INFO
    aaaaaa=True
    if aaaaaa:
        for i in ls.values():
            i.destroy()
        for i in l2s.values():
            i.destroy()
        for i in l3s.values():
            i.destroy()
        for i in l4s.values():
            i.destroy()
        d["state"] = "disabled"
        f["state"] = "disabled"
        del things[ln-1]
        ls={}
        l2s={}
        l3s={}
        l4s={}
        num=0
        for i in things:
            num += 1
            i1, i2 = i
            if i2 == "禁用":
                i3 = "此程序的进程将无法打开"
            else:
                i3 = "在操作此程序时键盘将被锁定"
            l = Frame(aaaa, bg="white", height="50")
            l.pack(side=TOP, fill=X)
            ls[num] = l
            l2 = Label(l, bg="white", bd=0, text="   {}   ".format(i1), font=("Microsoft YaHei", 9), height="2")
            l2.pack(side=LEFT)
            l2s[num] = l2
            l3 = Label(l, bg="white", bd=0, text="   {}   ".format(i2), font=("Microsoft YaHei", 9), height="2")
            l3.pack(side=RIGHT)
            l3s[num] = l3
            l4 = Button(l, bg="white", bd=0, text="   {}".format(i3), font=("Microsoft YaHei", 7), height="2",
                        state="disabled")
            l4.pack(side=RIGHT)
            l4s[num] = l4
            l.bind("<Button-1>", handlerAdaptor(doit, c=num))
            l2.bind("<Button-1>", handlerAdaptor(doit, c=num))
            l3.bind("<Button-1>", handlerAdaptor(doit, c=num))
            l4.bind("<Button-1>", handlerAdaptor(doit, c=num))
        aa = open("网课效率优化器-禁用/killer.txt", "w")
        aa.close()
        bb = open("网课效率优化器-限制/locker.txt", "w")
        bb.close()
        aa = open("网课效率优化器-禁用/killer.txt", "a")
        bb = open("网课效率优化器-限制/locker.txt", "a")
        for i in things:
            i1, i2 = i
            if i2 == "禁用":
                aa.write(i1)
                aa.write("\n")
            else:
                bb.write(i1)
                bb.write("\n")
        aa.close()
        aaaaa.yview("moveto", "0.0")
def tian2(event):
    global aaaaa, a, things,entry,entry2,ls, l2s, l3s,l4s,ln, a,d, f,things,ll,ll2,ll3

    for i in ls.values():
        i.destroy()
    for i in l2s.values():
        i.destroy()
    for i in l3s.values():
        i.destroy()
    for i in l4s.values():
        i.destroy()
    things.append((entry.get(), entry2.get()))
    ll.destroy()
    ll2.destroy()
    ll3.destroy()
    entry.destroy()
    entry2.destroy()
    ls = {}
    l2s = {}
    l3s = {}
    l4s = {}
    num = 0
    for i in things:
        num += 1
        i1, i2 = i
        if i2 == "禁用":
            i3 = "此程序的进程将无法打开"
        else:
            i3 = "在操作此程序时键盘将被锁定"
        l = Frame(aaaa, bg="white", height="50")
        l.pack(side=TOP, fill=X)
        ls[num] = l
        l2 = Label(l, bg="white", bd=0, text="   {}   ".format(i1), font=("Microsoft YaHei", 9), height="2")
        l2.pack(side=LEFT)
        l2s[num] = l2
        l3 = Label(l, bg="white", bd=0, text="   {}   ".format(i2), font=("Microsoft YaHei", 9), height="2")
        l3.pack(side=RIGHT)
        l3s[num] = l3
        l4 = Button(l, bg="white", bd=0, text="   {}".format(i3), font=("Microsoft YaHei", 7), height="2",
                    state="disabled")
        l4.pack(side=RIGHT)
        l4s[num] = l4
        l.bind("<Button-1>", handlerAdaptor(doit, c=num))
        l2.bind("<Button-1>", handlerAdaptor(doit, c=num))
        l3.bind("<Button-1>", handlerAdaptor(doit, c=num))
        l4.bind("<Button-1>", handlerAdaptor(doit, c=num))
    aa = open("网课效率优化器-禁用/killer.txt", "w")
    aa.close()
    bb = open("网课效率优化器-限制/locker.txt", "w")
    bb.close()
    aa = open("网课效率优化器-禁用/killer.txt", "a")
    bb = open("网课效率优化器-限制/locker.txt", "a")
    for i in things:
        i1, i2 = i
        if i2 == "禁用":
            aa.write(i1)
            aa.write("\n")
        else:
            bb.write(i1)
            bb.write("\n")
    aa.close()
    a.update()
    aaaaa.yview("moveto", "2.0")
def tian():
    global aaaaa,a,things,entry,entry2,ll,ll2,ll3,abcde,all,l4s,l3s,l2s,ls,d,f,edcba
    try:
        if abcde==1:
            tian2(1)
            abcde=0
    except:
        if False:
            print()
    try:
        if edcba==1:
            gai2(1)
            edcba=0
    except:
        if False:
            print()
    try:
        ls[ln]["bg"] = "white"
        l2s[ln]["bg"] = "white"
        l3s[ln]["bg"] = "white"
        l4s[ln]["bg"] = "white"
    except:
        if False:
            print()
    d["state"]="disabled"
    f["state"]="disabled"
    ll = Frame(aaaa, bg="#99d9ea", height="50")
    ll.pack(side=TOP, fill=X)
    ll2 = Label(ll, bg="#99d9ea", bd=0, text="   ", font=("Microsoft YaHei", 9), height="2")
    ll2.pack(side=LEFT)
    ll3 = Label(ll, bg="#99d9ea", bd=0, text="   ", font=("Microsoft YaHei", 9), height="2")
    ll3.pack(side=RIGHT)
    entry = Entry(ll, font=("Microsoft YaHei", 9),width=12)
    entry.pack(side=LEFT)
    entry2 = ttk.Combobox(ll, font=("Microsoft YaHei", 9),values=["禁用", "限制"],width=4,state="readonly")
    entry2.pack(side=RIGHT)
    entry2.current(0)
    entry.bind("<KeyPress-Return>",tian2)
    entry.bind("<KeyPress-Return>", handlerAdaptor(doit, c=len(l4s)+1))
    abcde=1
    a.update()
    aaaaa.yview("moveto", "2.0")
def gai2(event):
    global aaaaa, a, things, entry, entry2, ls, l2s, l3s, l4s, ln, a, d, f, things,ln2
    things[ln2-1]=(entry.get(), entry2.get())
    for i in ls.values():
        i.destroy()
    for i in l2s.values():
        i.destroy()
    for i in l3s.values():
        i.destroy()
    for i in l4s.values():
        i.destroy()
    d["state"]="normal"
    f["state"]="normal"
    entry.destroy()
    entry2.destroy()
    ls = {}
    l2s = {}
    l3s = {}
    l4s = {}
    num = 0
    for i in things:
        num += 1
        i1, i2 = i
        if i2 == "禁用":
            i3 = "此程序的进程将无法打开"
        else:
            i3 = "在操作此程序时键盘将被锁定"
        l = Frame(aaaa, bg="white", height="50")
        l.pack(side=TOP, fill=X)
        ls[num] = l
        l2 = Label(l, bg="white", bd=0, text="   {}   ".format(i1), font=("Microsoft YaHei", 9), height="2")
        l2.pack(side=LEFT)
        l2s[num] = l2
        l3 = Label(l, bg="white", bd=0, text="   {}   ".format(i2), font=("Microsoft YaHei", 9), height="2")
        l3.pack(side=RIGHT)
        l3s[num] = l3
        l4 = Button(l, bg="white", bd=0, text="   {}".format(i3), font=("Microsoft YaHei", 7), height="2",
                    state="disabled")
        l4.pack(side=RIGHT)
        l4s[num] = l4
        l.bind("<Button-1>", handlerAdaptor(doit, c=num))
        l2.bind("<Button-1>", handlerAdaptor(doit, c=num))
        l3.bind("<Button-1>", handlerAdaptor(doit, c=num))
        l4.bind("<Button-1>", handlerAdaptor(doit, c=num))
    aa = open("网课效率优化器-禁用/killer.txt", "w")
    aa.close()
    bb = open("网课效率优化器-限制/locker.txt", "w")
    bb.close()
    aa = open("网课效率优化器-禁用/killer.txt", "a")
    bb = open("网课效率优化器-限制/locker.txt", "a")
    for i in things:
        i1, i2 = i
        if i2 == "禁用":
            aa.write(i1)
            aa.write("\n")
        else:
            bb.write(i1)
            bb.write("\n")
    aa.close()
def gai():
    global ls,l2s,l3s,l4s,ln,a,d,f,edcba,things,ln2,entry,entry2
    cdcc=things[ln-1]
    cdcc1,cdcc2=cdcc
    ln2=ln
    l2s[ln]["text"]="   "
    l3s[ln]["text"] = "   "
    l4s[ln].destroy()
    d["state"] = "disabled"
    f["state"] = "disabled"
    hhh = StringVar()
    hhh.set(cdcc1)
    entry = Entry(ls[ln], font=("Microsoft YaHei", 9), width=12,textvariable = hhh)
    entry.pack(side=LEFT)
    entry2 = ttk.Combobox(ls[ln], font=("Microsoft YaHei", 9), values=["禁用", "限制"], width=4, state="readonly")
    entry2.pack(side=RIGHT)
    if cdcc2=="禁用":
        entry2.current(0)
    else:
        entry2.current(1)
    entry.bind("<KeyPress-Return>", gai2)
    edcba=1
def handlerAdaptor(fun,**kwds):
    return lambda event,fun=fun,kwds=kwds:fun(event,**kwds)
aa = open("网课效率优化器-禁用/killer.txt", "a")
aa.close()
try:
    aa = open("网课效率优化器-禁用/killer.txt", "r")
    a2 = aa.readlines()
except:
    aa = open("网课效率优化器-禁用/killer.txt", "r", encoding="utf-8")
    a2 = aa.readlines()
for i in range(len(a2)):
    try:
        a2[i] = a2[i].replace("\n", "")
    except:
        if False:
            print()
while True:
    try:
        a2.remove("")
    except:
        break
aa.close()
aa = open("网课效率优化器-限制/locker.txt", "a")
aa.close()
try:
    aa = open("网课效率优化器-限制/locker.txt", "r")
    bbb2 = aa.readlines()
except:
    aa = open("网课效率优化器-限制/locker.txt", "r", encoding="utf-8")
    bbb2 = aa.readlines()
for i in range(len(bbb2)):
    bbb2[i] = bbb2[i].replace("\n", "")
while True:
    try:
        bbb2.remove("")
    except:
        break
aa.close()
all=set()
for i in a2:
    all.add((i,"禁用"))
for i in bbb2:
    all.add((i,"限制"))
a=Tk()
a.title("网课效率优化器")
a.geometry("600x400+100+50")
qz=PhotoImage(file='网课.png')
a.iconphoto(True, qz)
a.resizable(width=0, height=1)
aaa=Frame(a,bd=2,)
aaa.pack(expand=YES,side=TOP,fill=BOTH)
b=Frame(aaa,bg="white",height="50")
b.pack(side=TOP,fill=X)
c=Button(b,bg="white",bd=0,text="   添加   ",font=("Microsoft YaHei",9),height="2",command=tian)
c.pack(side=RIGHT)
d=Button(b,bg="white",bd=0,text="   修改   ",font=("Microsoft YaHei",9),height="2",state="disabled",command=gai)
d.pack(side=RIGHT)
f=Button(b,bg="white",bd=0,text="   删除   ",font=("Microsoft YaHei",9),height="2",state="disabled",command=shan)
f.pack(side=RIGHT)
e=Label(b,bg="white",bd=0,text="   禁用/限制程序列表   ",font=("Microsoft YaHei",9),height="2")
e.pack(side=LEFT)
g=Frame(aaa,height=2)
g.pack(side=TOP,fill=X)
aaaaa=Canvas(aaa,bd=-2)
aaaaa.pack(expand=YES,side=LEFT,fill=BOTH)
aaaa=Frame(aaaaa)
a.update()
aaaaa.create_window(0,0, window=aaaa,width=a.winfo_width()-20,anchor=NW)
aaaa.bind("<Configure>", myfunction)
ls={}
l2s={}
l3s={}
l4s={}
things=[]
ln=1
num=0
for i in all:
    num+=1
    i1,i2=i
    things.append(i)
    if i2=="禁用":
        i3="此程序的进程将无法打开"
    else:
        i3 = "在操作此程序时键盘将被锁定"
    l = Frame(aaaa, bg="white", height="50")
    l.pack(side=TOP, fill=X)
    ls[num]=l
    l2 = Label(l, bg="white", bd=0, text="   {}   ".format(i1),font=("Microsoft YaHei", 9) ,height="2")
    l2.pack(side=LEFT)
    l2s[num]=l2
    l3 = Label(l, bg="white", bd=0, text="   {}   ".format(i2), font=("Microsoft YaHei", 9),height="2")
    l3.pack(side=RIGHT)
    l3s[num] = l3
    l4 =Button(l, bg="white", bd=0, text="   {}".format(i3), font=("Microsoft YaHei", 7),height="2",state="disabled")
    l4.pack(side=RIGHT)
    l4s[num] = l4
    l.bind("<Button-1>", handlerAdaptor(doit, c=num))
    l2.bind("<Button-1>", handlerAdaptor(doit, c=num))
    l3.bind("<Button-1>", handlerAdaptor(doit, c=num))
    l4.bind("<Button-1>", handlerAdaptor(doit, c=num))
myscrollbar = Scrollbar(aaaaa, orient="vertical", command=aaaaa.yview)
aaaaa.yview("moveto","0.0")
myscrollbar.pack(side=RIGHT, fill=Y)
aaaaa.configure(yscrollcommand=myscrollbar.set)
a.mainloop()

